package foo.bar.wiki.web.action.general;

import foo.bar.wiki.web.action.BaseActionBean;
import foo.bar.wiki.web.nonextension.NullResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.StreamingResolution;
import net.sourceforge.stripes.action.DefaultHandler;

import java.io.InputStream;

/**
 * @author tmjee
 * @version $Date$ $Id$
 */
public abstract class AbstractImageActionBean extends BaseActionBean {

        @DefaultHandler
        public Resolution view() {
            InputStream is = getContext().getServletContext().getResourceAsStream(generateThemePath(getResourcePath()));
            if (is == null) { // try defaut theme
                is = getContext().getServletContext().getResourceAsStream(generateDefaultThemePath(getResourcePath()));
            }
            if (is != null) {
                return new StreamingResolution(getResourceMimeType(), is);
            }
            return new NullResolution();
        }



        protected abstract String getResourcePath();
        protected abstract String getResourceMimeType();


}
